package academic.emailClient.control.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import academic.emailClient.EmailClientImpl;
import academic.emailClient.model.EmailClientModel;
import academic.emailClient.view.EmailClientViewInterface;

/**
 * Class tell the view that whenever an action to do one 
 * of the following "cancel, save to draft, save to To send, send button" 
 * is clicked how to execute .And the action performed for each of which
 * is calling a new instance of the related class..
 *  
 * * @author 
 *
 */
public class ComposeMessageListener implements ActionListener{
	
	private EmailClientViewInterface view;
	private EmailClientModel model;
	
/**
 * constructor
 * 	
 * @param view
 * @param model
 */
	public ComposeMessageListener(EmailClientViewInterface view, EmailClientModel model) {
		super();
		this.view = view;
		this.model = model;
	}

	/**
	 * handle the item State Changed event
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		view.showComposeMessage();
		view.addCancelMessageListener(new CancelEmailMsgControllerListener(view));
		view.addSaveMessageListener(new SaveEmailMsgControllerListener(view, model));
		view.addSendMessageListener(new SendEmailMsgControllerListener(view, model));
		view.addToSentEmailButtonListener(new SaveToSentListener(view, model));	
		view.adddraftEmailButtonListener(new SaveDraftListener(view, model));
		view.addLetterMouseListener(new LetterMouseListener(view, model));
		try {
			view.addComposeMessageTemplateCbListener(new ComposeMailTemplateChangedListener(view, model));
			
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}		
	}
}
